package com.seleniti.enpareja.controller.ui.view;

import org.ioc.commons.flowcontrol.actioncontroller.ActionController;
import org.ioc.commons.flowcontrol.eventbus.EventBus;
import org.ioc.commons.flowcontrol.operationmanager.OperationManager;
import org.ioc.commons.model.globaldata.GlobalDataController.Consumer;
import org.ioc.commons.model.globaldata.IsGlobalDataConsumer;
import org.ioc.commons.utils.FormatterLogger;

import com.seleniti.enpareja.controller.common.GlobalData;
import com.seleniti.enpareja.controller.ui.base.EnParejaViewBasePresenter;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView.Action;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView.Event;
import com.seleniti.enpareja.controller.ui.view.SolveNoPasswordSetView.Operation;

/**
 * Presenter for the Login view
 * 
 * @author Jesús Lunar Pérez
 * 
 */
public class SolveNoPasswordSetViewPresenter
		extends
		EnParejaViewBasePresenter<SolveNoPasswordSetView, SolveNoPasswordSetView.Event, SolveNoPasswordSetView.Operation, SolveNoPasswordSetView.Action>
		implements SolveNoPasswordSetView.Presenter, IsGlobalDataConsumer<GlobalData> {

	private static final FormatterLogger logger = FormatterLogger.getLogger(SolveNoPasswordSetViewPresenter.class);

	private Consumer<GlobalData> consumer;

	public SolveNoPasswordSetViewPresenter(SolveNoPasswordSetView display, EventBus<Event> eventbus,
			OperationManager<Operation> operationManager, ActionController<Action> actionController) {
		super(display, eventbus, operationManager, actionController);
		this.consumer = this.globalDataController.registerGlobalDataConsumer(this);
		this.consumer.requires(GlobalData.UserAgent);
	}

	@Override
	public void onInitDisplay() {
		super.onInitDisplay();

		shell.gettingStartedInfoVisible().setVisible(false);
	}

	@Override
	public void onActive() {
		super.onActive();

		shell.refreshButtonVisibility().setVisible(false);
		this.consumer.ensureRequirements();
	}

	@Override
	public void onRequiredGlobalDataReady() {
		showGoBackButtonIfRequired();
	}

	@Override
	public void onRequiredGlobalDataNotReadyYet() {
		/*
		 * Nothing to do
		 */
	}

	@Override
	public void onRequiredGlobalDataUpdated(GlobalData globalDataUpdated) {
		showGoBackButtonIfRequired();
	}

	@Override
	public void onGoBack() {
		this.placeController.goBack();
	}

}
